<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">



  
  
    
    
  <script src="/dxl/lib/pace/pace.min.js?v=1.0.2"></script>
  <link href="/dxl/lib/pace/pace-theme-minimal.min.css?v=1.0.2" rel="stylesheet">







<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/dxl/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/dxl/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/dxl/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/dxl/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/dxl/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/dxl/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/dxl/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="面试题,">










<meta name="description" content="一、基础知识1.1requests模块12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364- 爬取数据流程：        - 1.指定url        - 2.发起请求        - 3.获取响应数据">
<meta name="keywords" content="面试题">
<meta property="og:type" content="article">
<meta property="og:title" content="Django">
<meta property="og:url" content="http://yoursite.com/2019/09/20/【内容回顾】爬虫/index.html">
<meta property="og:site_name" content="我的快乐时光">
<meta property="og:description" content="一、基础知识1.1requests模块12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364- 爬取数据流程：        - 1.指定url        - 2.发起请求        - 3.获取响应数据">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2019-09-21T07:17:44.454Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Django">
<meta name="twitter:description" content="一、基础知识1.1requests模块12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364- 爬取数据流程：        - 1.指定url        - 2.发起请求        - 3.获取响应数据">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/dxl/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":true,"scrollpercent":true,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2019/09/20/【内容回顾】爬虫/">





  <title>Django | 我的快乐时光</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/dxl/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">我的快乐时光</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/dxl/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/dxl/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/dxl/2019/09/20/【内容回顾】爬虫/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content>
      <meta itemprop="description" content>
      <meta itemprop="image" content="/dxl/images/avatar.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="我的快乐时光">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Django</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-09-20T20:05:12+08:00">
                2019-09-20
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/dxl/categories/面试题/" itemprop="url" rel="index">
                    <span itemprop="name">面试题</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/dxl/2019/09/20/【内容回顾】爬虫/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count valine-comment-count" data-xid="/dxl/2019/09/20/【内容回顾】爬虫/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          

          
            <span class="post-meta-divider">|</span>
            <span class="page-pv">本文总阅读量
            <span class="busuanzi-value" id="busuanzi_value_page_pv"></span>次
            </span>
          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="一、基础知识"><a href="#一、基础知识" class="headerlink" title="一、基础知识"></a>一、基础知识</h2><h3 id="1-1requests模块"><a href="#1-1requests模块" class="headerlink" title="1.1requests模块"></a>1.1requests模块</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br></pre></td><td class="code"><pre><span class="line">- 爬取数据流程：</span><br><span class="line">        - <span class="number">1.</span>指定url</span><br><span class="line">        - <span class="number">2.</span>发起请求</span><br><span class="line">        - <span class="number">3.</span>获取响应数据</span><br><span class="line">        - <span class="number">4.</span>数据解析</span><br><span class="line">        - <span class="number">5.</span>持久化存储</span><br><span class="line">    - get，post作用：发起请求</span><br><span class="line">    - get，post参数：</span><br><span class="line">        - url</span><br><span class="line">        - data/prames</span><br><span class="line">        - headers</span><br><span class="line">        - proxies</span><br><span class="line">    - 处理ajax动态加载的数据：</span><br><span class="line">        - 动态加载的数据：通过另一个请求请求到的数据</span><br><span class="line">        - 通过抓包工具捕获请求对应的数据包，数据包之间实现局部或者全局搜索</span><br><span class="line">    - 模拟登陆：</span><br><span class="line">        - 对点击登陆按钮对应的post请求进行请求发送</span><br><span class="line">        - 动态变化的请求参数：</span><br><span class="line">            - 一般会隐藏在前台页面</span><br><span class="line">    - 打码平台使用：</span><br><span class="line">        - 超级鹰，云打码</span><br><span class="line">    - cookie的处理：</span><br><span class="line">        - 手动处理</span><br><span class="line">            - 将cookie从抓包工具对应数据包的头信息中进行捕获，粘贴在headers中</span><br><span class="line">        - requests.Session()自动处理</span><br><span class="line">            - session。requests.Session()</span><br><span class="line">    - 代理ip：</span><br><span class="line">        - 类型：http，https</span><br><span class="line">    - 线程池：</span><br><span class="line">        - dummy <span class="keyword">import</span> Pool</span><br><span class="line">        - map(func,list)</span><br><span class="line">    - 图片懒加载：  伪属性 </span><br><span class="line">    - 单线程+多任务异步协程</span><br><span class="line">        - 协程：对象。一个被aynic关键字修饰的函数定义，该函数被调用后会马上返回一个协程对象。</span><br><span class="line">        - 任务对象：就是对协程对象的进一步封装。</span><br><span class="line">            - 绑定回调：<span class="function"><span class="keyword">def</span> <span class="title">callback</span>（<span class="title">task</span>）：<span class="title">return</span> <span class="title">task</span>.<span class="title">result</span><span class="params">()</span></span></span><br><span class="line"><span class="function">            - <span class="title">task</span>.<span class="title">add_done_callback</span><span class="params">(callback)</span></span></span><br><span class="line"><span class="function">        - 任务列表：多个任务对象</span></span><br><span class="line"><span class="function">        - 事件循环对象：任务列表是需要注册到事件循环对象中，然后事件循环开启后，则会将任务列表中的每一个任务对象进行异步调用。</span></span><br><span class="line"><span class="function">        - <span class="title">aiohttp</span>:</span>是一个基于异步的网络请求模块</span><br><span class="line">- 数据解析：<span class="number">1</span>定位标签<span class="number">2</span>数据提取</span><br><span class="line">    - 正则表达式：</span><br><span class="line">    - bs4：</span><br><span class="line">    - xpath：</span><br><span class="line">- selenium</span><br><span class="line">    - 关联：</span><br><span class="line">        - <span class="number">1.</span>便捷的捕获到动态加载的数据（可见及可得）</span><br><span class="line">        - <span class="number">2.</span>实现模拟登陆</span><br><span class="line">    - 作用：实现浏览器自动化的相关操作</span><br><span class="line">    - 使用流程：</span><br><span class="line">        - 环境安装</span><br><span class="line">        - 下载浏览器的驱动程序</span><br><span class="line">        - 实例化浏览器对象</span><br><span class="line">        - 制定相关的行为动作</span><br><span class="line">        - 关闭浏览器</span><br><span class="line">    - find系列函数：</span><br><span class="line">        - 定位标签</span><br><span class="line">    - switch_to.frame（iframe的id）函数</span><br><span class="line">        - 切换iframe</span><br><span class="line">    - 无头浏览器</span><br><span class="line">    - 规避监测</span><br><span class="line">    - phantomJs：</span><br><span class="line">    - 谷歌无头浏览器：</span><br><span class="line">    - 动作连：<span class="keyword">from</span> selenium.webdriver <span class="keyword">import</span> ActionChains</span><br></pre></td></tr></table></figure>

<h2 id="1-2scrapy"><a href="#1-2scrapy" class="headerlink" title="1.2scrapy"></a>1.2scrapy</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br></pre></td><td class="code"><pre><span class="line">- 项目创建流程：</span><br><span class="line">        - scrapy startproject ProName</span><br><span class="line">        - cd ProName</span><br><span class="line">        - scrapy genspider spiderName www.xxx.com</span><br><span class="line">        - scrapy crawl spiderName</span><br><span class="line">    - 数据解析：</span><br><span class="line">        - response.xpath(’xpath表达式‘)</span><br><span class="line">        - xpath返回的列表中存储的是Selector对象，解析的字符串类型的数据是被存储在了该对象中。获取字符串类型的数据必须extract()或者extract_first()</span><br><span class="line">    - 持久化存储：</span><br><span class="line">        - 基于终端指令的持久化存储</span><br><span class="line">            - scrapy crawl spiderName -o filePath</span><br><span class="line">        - 管道：</span><br><span class="line">            - 数据解析</span><br><span class="line">            - 存储封装到item类型的对象中</span><br><span class="line">            - 将item提交给管道</span><br><span class="line">            - 在管道类的process_item（item，spider）方法中接收item，对item进行任意形式的持久化存储</span><br><span class="line">            - 在settings中开启管道</span><br><span class="line">            - 注意事项：</span><br><span class="line">                - 开启管道的时候，管道的优先级，数值越小优先级越高</span><br><span class="line">                - 一个管道类表示将数据存储到某一个具体的平台中</span><br><span class="line">                - process_item的<span class="keyword">return</span> item表示的是将item传递给下一个即将被执行的管道类</span><br><span class="line">                - 爬虫类提交的item只会提交给优先级最高的管道</span><br><span class="line">    - 处理分页数据爬取：</span><br><span class="line">        - 全站数据爬取：</span><br><span class="line">            - 手动请求发送：<span class="keyword">yield</span> scrapy.Request/FormReqest（url,callback,formdata）</span><br><span class="line">    - post请求</span><br><span class="line">    - cookie处理：</span><br><span class="line">    - 日志等级：</span><br><span class="line">        - LOG_LEVEL = <span class="string">'ERROR'</span></span><br><span class="line">    - 请求传参：</span><br><span class="line">        - 使用场景：</span><br><span class="line">            - 实现数据的深度爬取（爬取的数据没有存在同一张页面中）</span><br><span class="line">        - 如何实现请求传参：</span><br><span class="line">            - <span class="keyword">yield</span> scrapy.Request/FormReqest（url,callback,formdata,meta=&#123;&#125;）:meta就会将自己传递给callback，在callback中使用response.meta进行字典的接收</span><br><span class="line">    - 五大核心组件原理：</span><br><span class="line">    - 下载中间件：</span><br><span class="line">        - process_request：</span><br><span class="line">            - UA伪装</span><br><span class="line">                - request.headers[<span class="string">'User-Agent'</span>] = <span class="string">'xxx'</span></span><br><span class="line">            - 代理设定</span><br><span class="line">                - request.meta[<span class="string">'proxy'</span>] = <span class="string">'http://ip:port'</span></span><br><span class="line">        - process_response</span><br><span class="line">            - 篡改响应内容或者替换响应对象</span><br><span class="line">        - process_exception：</span><br><span class="line">            - 对异常的请求进行拦截</span><br><span class="line">            - 对异常的请求进行修正</span><br><span class="line">            - rerurn request的操作将修正后的请求对象进行重新的请求发送</span><br><span class="line">    - UA池和代理池：</span><br><span class="line">    - selenium在scrapy中的应用：</span><br><span class="line">        - <span class="number">1.</span>在爬虫类添加一个属性，将属性作为浏览器对象。</span><br><span class="line">        - <span class="number">2.</span>爬虫类的closed(self,spider)方法中关闭浏览器对象</span><br><span class="line">        - <span class="number">3.</span>在中间件的process_response中获取浏览器对象，实现自动化相关的操作</span><br><span class="line">    - crawlSpider：</span><br><span class="line">        - 全站数据爬取</span><br><span class="line">        - LinkExtractor（allow=<span class="string">'正则'</span>）</span><br><span class="line">            - 根据指定规则（正则）进行连接（url）的提取</span><br><span class="line">        - Rule（link，callback，follow=<span class="literal">True</span>）</span><br><span class="line">            - 接收连接提取器提取到的连接，对其进行请求发送，然后将请求到的数据进行指定规则（callback）的解析</span><br><span class="line">- 分布式</span><br><span class="line">    - scrapy为何不能实现分布式：</span><br><span class="line">        - 调度器和管道不可以被共享</span><br><span class="line">    - scrapy-redis的作用：</span><br><span class="line">        - 提供了可以被共享的管道和调度器</span><br><span class="line">    - 实现分布式的方式：scrapy+redis</span><br><span class="line">    - 流程：</span><br></pre></td></tr></table></figure>

<h3 id="1-3增量式爬虫"><a href="#1-3增量式爬虫" class="headerlink" title="1.3增量式爬虫"></a>1.3增量式爬虫</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">数据指纹：一组数据的唯一标识。</span><br></pre></td></tr></table></figure>

<h2 id="1-4反扒机制总结"><a href="#1-4反扒机制总结" class="headerlink" title="1.4反扒机制总结"></a>1.4反扒机制总结</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">- robots.txt</span><br><span class="line">- UA检测</span><br><span class="line">- 验证码</span><br><span class="line">- 数据加密</span><br><span class="line">- cookie</span><br><span class="line">- 禁IP</span><br><span class="line">- 动态token</span><br><span class="line">- 数据动态加载</span><br><span class="line">- js混淆</span><br><span class="line">- 图片懒加载</span><br></pre></td></tr></table></figure>

<h2 id="1-5数据清洗"><a href="#1-5数据清洗" class="headerlink" title="1.5数据清洗"></a>1.5数据清洗</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">- 空值检测删除空值所在的行数据：df.dropna(axis=0)</span><br><span class="line">- 空值检测填充空值：df.fillna(method=&apos;ffill&apos;,axis=0)</span><br><span class="line">- 异常值检测和过滤：</span><br><span class="line">    - 判定异常值的条件</span><br><span class="line">- 重复行检测和删除：</span><br><span class="line">    - df.drop_duplicated(keep=&apos;first&apos;)</span><br></pre></td></tr></table></figure>

<h2 id="1-6总结"><a href="#1-6总结" class="headerlink" title="1.6总结"></a>1.6总结</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line">- 掌握哪些基于爬虫模块：</span><br><span class="line">    - 网络请求：urllib,requests,aiohttp</span><br><span class="line">    - 数据解析：re,bs4,lxml</span><br><span class="line">    - selenium</span><br><span class="line">    - dummy,asyncio,pyExcl</span><br><span class="line">- 比较难的反爬：</span><br><span class="line">    - js加密</span><br><span class="line">    - js混淆</span><br><span class="line">    - 动态请求参数</span><br><span class="line">    - 动态加载的数据</span><br><span class="line">- 移动端数据的抓取：</span><br><span class="line">    - fiddler，青花瓷，miteproxy</span><br><span class="line">- 抓取过哪些类型的数据，量级是多少？</span><br><span class="line">    - 电商，医疗，新闻资讯，股票，金融，相关工程数据</span><br><span class="line">- 爬虫框架</span><br><span class="line">    - scrapy，pyspider</span><br><span class="line">- 谈谈对scrapy的了解</span><br><span class="line">    - scrapy的功能模块</span><br><span class="line">    - 五大核心组件的工作流程</span><br><span class="line">- 中间件的了解</span><br><span class="line">    - 下载中间件</span><br><span class="line">        - 作用：批量拦截请求和响应</span><br><span class="line">            - 拦截请求</span><br><span class="line">                - UA伪装，代理</span><br><span class="line">            - 拦截响应</span><br><span class="line">                - 篡改响应内容</span><br><span class="line">- 如何提升数据爬取的效率</span><br><span class="line">    - requests+线程池</span><br><span class="line">    - asyncio+aiohttp</span><br><span class="line">    - scrapy</span><br><span class="line">    - 分布式</span><br><span class="line">- 了解过机器学习</span><br><span class="line">    - sklearn</span><br><span class="line">        - 线性回归</span><br><span class="line">        - KNN</span><br></pre></td></tr></table></figure>

<h2 id="二、面试题"><a href="#二、面试题" class="headerlink" title="二、面试题"></a>二、面试题</h2><p>1、如何提升爬虫的效率</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">线程池</span><br><span class="line">scrapy配置文件相关配置（禁用cookie，禁止重试，减小下载超时，增加并发，日志等级）</span><br></pre></td></tr></table></figure>

<p>2、scrapy核心组件工作流程</p>
<p>3、scrapy中如何设置代理（两种方法）</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">- 中间件</span><br><span class="line">- 环境变量（os.environ[&apos;HTTPS_PROXY&apos;] = &apos;https:ip:port&apos;）</span><br></pre></td></tr></table></figure>

<p>4、scrapy如何实现限速</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">DOWNLOAD_DELAY = 1</span><br></pre></td></tr></table></figure>

<p>5、scrapy如何实现暂停爬虫</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">- JOBDIR=&apos;sharejs.com&apos;</span><br><span class="line">- control-C</span><br></pre></td></tr></table></figure>

<p>6、pipeline如何丢弃一个item对象</p>
<p>7、scrapy-redis组件作用</p>
<p>8、实现深度和广度优先:默认为深度优先。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">- DEPTH_PRIORITY = 1</span><br><span class="line">- SCHEDULER_DISK_QUEUE = &apos;scrapy.squeues.PickleFifoDiskQueue&apos;</span><br><span class="line">- SCHEDULER_MEMORY_QUEUE = &apos;scrapy.squeues.FifoMemoryQueue&apos;</span><br><span class="line">- 广度优先：不全部保留结点，占用空间少；运行速度慢</span><br><span class="line">- 深度优先：保留全部结点，占用空间大；运行速度快</span><br><span class="line">- https://www.cnblogs.com/zhaof/p/7092400.html</span><br></pre></td></tr></table></figure>

<p>9、通过在settings.py中设置DEPTH_LIMIT的值可以限制爬取深度，这个深度是与start_urls中定义url的相对值。也就是相对url的深度。例如定义url为：<a href="http://www.domz.com/game/,DEPTH_LIMIT=1那么限制爬取的只能是此url下一级的网页。深度大于设置值的将被ignore。" target="_blank" rel="noopener">http://www.domz.com/game/,DEPTH_LIMIT=1那么限制爬取的只能是此url下一级的网页。深度大于设置值的将被ignore。</a></p>

      
    </div>
    
    
    

    

    

    
      <div>
        <ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者：</strong>
    
  </li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="http://yoursite.com/2019/09/20/【内容回顾】爬虫/" title="Django">http://yoursite.com/2019/09/20/【内容回顾】爬虫/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>
    本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/3.0/" rel="external nofollow" target="_blank">CC BY-NC-SA 3.0</a> 许可协议。转载请注明出处！
  </li>
</ul>

      </div>
    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/dxl/tags/面试题/" rel="tag"># 面试题</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/dxl/2019/09/20/【内容回顾】03-1python基础/" rel="next" title="python基础">
                <i class="fa fa-chevron-left"></i> python基础
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/dxl/2019/09/20/【面试题】01-1绿皮书一/" rel="prev" title="绿皮书01">
                绿皮书01 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
    </div>
  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/dxl/images/avatar.png" alt>
            
              <p class="site-author-name" itemprop="name"></p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/dxl/archives">
              
                  <span class="site-state-item-count">41</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/dxl/categories/index.html">
                  <span class="site-state-item-count">6</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/dxl/tags/index.html">
                  <span class="site-state-item-count">6</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          

          
          

          
          
            <div class="links-of-blogroll motion-element links-of-blogroll-inline">
              <div class="links-of-blogroll-title">
                <i class="fa  fa-fw fa-sign-out"></i>
                我的友链
              </div>
              <ul class="links-of-blogroll-list">
                
                  <li class="links-of-blogroll-item">
                    <a href="tencent://message/?Menu=yes&uin=1258517737&Site=QQ%E6%9E%81%E5%AE%A2&Service=300&sigT=45a1e5847943b64c6ff3990f8a9e644d2b31356cb0b4ac6b24663a3c8dd0f8aa12a595b1714f9d45/" title="申请坑位" target="_blank">申请坑位</a>
                  </li>
                
              </ul>
            </div>
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#一、基础知识"><span class="nav-number">1.</span> <span class="nav-text">一、基础知识</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-1requests模块"><span class="nav-number">1.1.</span> <span class="nav-text">1.1requests模块</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1-2scrapy"><span class="nav-number">2.</span> <span class="nav-text">1.2scrapy</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-3增量式爬虫"><span class="nav-number">2.1.</span> <span class="nav-text">1.3增量式爬虫</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1-4反扒机制总结"><span class="nav-number">3.</span> <span class="nav-text">1.4反扒机制总结</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1-5数据清洗"><span class="nav-number">4.</span> <span class="nav-text">1.5数据清洗</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1-6总结"><span class="nav-number">5.</span> <span class="nav-text">1.6总结</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#二、面试题"><span class="nav-number">6.</span> <span class="nav-text">二、面试题</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      
        <div class="back-to-top">
          <i class="fa fa-arrow-up"></i>
          
            <span id="scrollpercent"><span>0</span>%</span>
          
        </div>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-hand-peace-o"></i>
  </span>
  <span class="author" itemprop="copyrightHolder"></span>

  
</div>









        
<div class="busuanzi-count">
  <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv">
      本站访客数
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
      人次
    </span>
  

  
    <span class="site-pv">
      本站总访问量
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
      次
    </span>
  
</div>








        
      </div>
    </footer>

    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/dxl/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/dxl/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/dxl/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/dxl/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/dxl/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/dxl/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/dxl/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/dxl/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/dxl/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/dxl/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/dxl/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/dxl/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/dxl/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  










  <script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
  <script src="//unpkg.com/valine/dist/Valine.min.js"></script>
  
  <script type="text/javascript">
    var GUEST = ['nick','mail','link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item=>{
      return GUEST.indexOf(item)>-1;
    });
    new Valine({
        el: '#comments' ,
        verify: false,
        notify: false,
        appId: '13B0JGDuA6ttduN8AQaR8CzF-gzGzoHsz',
        appKey: 'I13r9r5mVgq4jQYpYy6V4gW3',
        placeholder: '欢迎大佬指点~~~',
        avatar:'mm',
        guest_info:guest,
        pageSize:'10' || 10,
    });
  </script>



  





  

  

  

  
  

  

  

  

</body>
</html>
